package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.api.domain.vo.SkuLockVo;
import com.spzx.product.api.domain.vo.SkuStockVo;
import com.spzx.product.service.SkuStockService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName SkuStockController
 * @Author 波
 * @Date 2024/8/5 19:57
 */
@RestController
@RequestMapping("/skuStock")
@Tag(name = "sku库存管理")
public class SkuStockController extends BaseController {
    @Autowired
    private SkuStockService skuStockService;

    @Operation(summary = "查询skuStockVo信息")
    @InnerAuth
    @GetMapping("/getSkuStockVo/{skuId}")
    public R<SkuStockVo> getSkuStockVo(@PathVariable("skuId") Long skuId) {
        return R.ok(skuStockService.getSkuStockVo(skuId));
    }

    @InnerAuth
    @Operation(summary = "检查与锁定库存")
    @PostMapping("checkAndLock/{orderNo}")
    public R<String> checkAndLock(@PathVariable("orderNo") String orderNo, @RequestBody List<SkuLockVo> skuLockVoList){
        try {
            return R.ok(skuStockService.checkAndLock(orderNo,skuLockVoList));
        }catch (Exception e){
            e.printStackTrace();
            return R.fail();
        }
    }

}
